package com.hnevc.yourhealthmanager.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnevc.yourhealthmanager.dto.SportRecordDTO;
import com.hnevc.yourhealthmanager.entity.HealthPlane;
import com.hnevc.yourhealthmanager.entity.SportRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SportRecordMapper extends BaseMapper<SportRecord> {
    @Select("select id,user_id,sport_name,sport_id,sport_image,sport_duration,sport_steps,sport_times,sport_date from sport_record_table where user_id = #{userId}")
    List<SportRecord> selectByUserId(@Param("userId") Integer userId);


    @Select("select srt.id,user_id,username,sport_id,sport_name,sport_image,sport_duration,sport_steps,sport_times,sport_date " +
            "from sport_record_table as srt, health_user_table as hut, sport_meta_table as smt " +
            "where srt.user_id= hut.id and srt.sport_id = smt.id and user_id = #{userId}")
    List<SportRecordDTO> getSportRecordListByUserId(@Param("userId") Integer userId);

    @Select("select srt.id,user_id,username,sport_id,sport_name,srt.sport_image,sport_duration,sport_steps,sport_times,sport_date " +
            "from sport_record_table as srt left join health_user_table as hut on srt.user_id = hut.id " +
            "left join  sport_meta_table as smt  on sport_id = smt.id " +
            "where user_id = #{healthPlane.userId}  " +
            "and sport_date between #{healthPlane.startDate} and #{healthPlane.endDate} ")
    List<SportRecordDTO> getSportRecordListByHealthPlane(@Param("healthPlane") HealthPlane healthPlane);

    @Select("select srt.id,srt.user_id,username,srt.sport_id,sport_name,sport_image,sport_duration,sport_steps,sport_times,sport_date " +
            "from sport_record_table as srt, health_user_table as hut, sport_meta_table as smt " +
            "where srt.user_id= hut.id and srt.sport_id = smt.id  and user_id = #{healthPlane.userId} " +
            "and sport_date between #{healthPlane.startDate} and #{healthPlane.endDate}  " +
            "and Month(sport_date)=#{month} and Year(sport_date)=#{year}")
    List<SportRecordDTO> getSportRecordListByPlaneMonth(@Param("healthPlane") HealthPlane healthPlane, @Param("month") Integer month, @Param("year") Integer year);
}